<%--
  Created by IntelliJ IDEA.
  User: sunhao
  Date: 2015/11/12 0012
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>欠费列表</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%--<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">--%>
    <link href="/static/bui/css/bs3/dpl.css" rel="stylesheet" type="text/css"/>
    <link href="/static/bui/css/bs3/bui.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<div class="panel">
    <div class="panel-header">
        <h3>欠费列表</h3>
    </div>
    <div class="panel-body">
        <%--<form id="searchForm" class="form-horizontal well" action="/accounts/find" method="post">--%>
            <%--<div class="row">--%>
                <%--<div class="control-group span8">--%>
                    <%--<label class="control-label">开始时间：</label>--%>

                    <%--<div class="controls">--%>
                        <%--<input type="text" class="calendar" name="startDate" style="width: auto"/>--%>
                    <%--</div>--%>
                <%--</div>--%>

                <%--<div class="control-group span8">--%>
                    <%--<label class="control-label">结束时间：</label>--%>

                    <%--<div class="controls">--%>
                        <%--<input type="text" class="calendar" name="endDate" style="width: auto"/>--%>
                    <%--</div>--%>
                <%--</div>--%>
            <%--</div>--%>
            <%--<div class="row">--%>
                <%--<div class="control-group span8">--%>
                    <%--<label class="control-label">学生姓名：</label>--%>

                    <%--<div class="controls">--%>
                        <%--<select name="student" class="input-normal bui-form-field-select bui-form-field"--%>
                                <%--aria-disabled="false" aria-pressed="false">--%>
                            <%--<option value="">请选择</option>--%>
                            <%--<c:forEach items="${students}" var="p">--%>
                                <%--<option value="${p._id}">${p.name}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</select>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="control-group span8">--%>
                    <%--<label class="control-label">是否结清：</label>--%>

                    <%--<div class="controls">--%>
                        <%--<select name="status" class="input-normal bui-form-field-select bui-form-field"--%>
                                <%--aria-disabled="false" aria-pressed="false">--%>
                            <%--<option value="-1" selected>请选择</option>--%>
                            <%--<option value="0" >未结清</option>--%>
                            <%--<option value="1">已结清</option>--%>
                        <%--</select>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="span3 offset2">--%>
                    <%--<input value="搜索" type="submit" id="btnSearch" class="button button-primary"/>--%>
                <%--</div>--%>
            <%--</div>--%>
        <%--</form>--%>

        <div class="row" style="margin-top: 50px">
            <div class="span21 offset3 control-row-auto">
                <div id="grid"></div>
                <input type="hidden" name="lesson">
            </div>
        </div>


        <script type="text/javascript" src="/static/bui/js/jquery-1.8.1.min.js"></script>
        <script type="text/javascript" src="/static/bui/js/bui.js"></script>
        <script type="text/javascript" src="/static/bui/js/config.js"></script>
        <script type="text/javascript">
            BUI.use('common/page');
            <%--</script>--%>
            <%--<script type="text/javascript">--%>
            BUI.use(['bui/grid', 'bui/data', 'bui/form'], function (Grid, Data, Form) {
                var columns = [
//              {title: 'ID', dataIndex: '_id', width: '40%'},
                            {title: '欠费开始日期', dataIndex: 'date', width: '15%'},
                            {title: '学生姓名', dataIndex: 'student', width: '15%'},
                            {title: '欠费内容', dataIndex: 'action', width: '60%'},
                            {title: '是否结清', dataIndex: 'status', width: '10%'}
                        ],
                //默认的数据
                        data = [
                            <c:forEach items="${accounts}" var="p">
                            {
                                _id: '${p._id}',
                                date: '${p.date}',
                                student: '${p.student}',
                                action: '${p.action}',
                                status: '${p.status}'
                            },
                            </c:forEach>
                        ],
                        store = new Data.Store({
                            data: data,
                            pageSize: 20
                        }),
                        editing = new Grid.Plugins.DialogEditing({
                            contentId: 'content',
                            triggerCls: 'btn-edit',
                            editor: {
                                focusable: false,
                                success: function () {
                                    var editType = editing.get('editType'),
                                            edtor = this,
                                            form = edtor.get("form");
                                    form.valid();
                                    if (form.isValid()) {
                                        this.close();
                                        if (editType == 'add') {
                                            $.ajax({
                                                type: 'post',
                                                url: '/manage/addExpend',
                                                data: $("#J_Form").serialize(),
                                                success: function (msg) {
                                                    if (msg == 'success') {
                                                        msg = "添加成功！";
                                                        BUI.Message.Alert(msg, function () {
                                                            window.location.href = '/manage/expend.do';
                                                        }, 'success')
                                                    } else {
                                                        msg = "添加失败";
                                                        BUI.Message.Alert(msg, function () {
                                                            window.location.href = '/jsp/error/noAuthority.jsp';
                                                        }, 'error')
                                                    }

                                                }
                                            })
                                        } else {
                                            $.ajax({
                                                type: 'post',
                                                url: '/manage/updateExpend',
                                                data: $("#J_Form").serialize(),
                                                success: function (msg) {
                                                    if (msg == 'success') {
                                                        msg = '修改成功！';
                                                        BUI.Message.Alert(msg, function () {
                                                            window.location.href = '/manage/expend.do';
                                                        }, 'success')
                                                    } else {
                                                        msg = '修改失败';
                                                        BUI.Message.Alert(msg, function () {
                                                            window.location.href = '/jsp/error/noAuthority.jsp';
                                                        }, 'error')
                                                    }
                                                }
                                            })
                                        }
                                    }
                                }
                            }
                        }),
                        grid = new Grid.Grid({
                            render: '#grid',
                            columns: columns,
                            width: '100%',
//                    forceFit: true,
                            plugins: [Grid.Plugins.AutoFit],
                            store: store,
                            bbar: {
                                pagingBar: true,
                                elCls: 'image-pbar'
                            },
                            plugins: [Grid.Plugins.CheckSelection, editing],
                            tbar: {
                                items: [{
                                    btnCls: 'button button-small',
                                    text: '<i class="icon-circle-arrow-left"></i>管理员手动结清收据欠款',
                                    listeners: {
                                        'click': payFunction
                                    }
                                }]
                            }
                        });
                grid.render();


                function payFunction() {
                    var selections = grid.getSelection();
                    delItems(selections);
                }

                function delItems(items) {
                    var _ids = []
                    BUI.each(items, function (item) {
                        _ids.push(item._id)
                    });
                    if (_ids.length == 1) {
                        if (_ids.length) {
                            BUI.Message.Confirm('请再次确认收据号和欠款信息是否一致？（无收据信息无需此操作）', function () {
                                $.ajax({
                                    type: 'POST',
                                    url: '/accounts/pay?_ids=' + _ids,
                                    success: function (msg) {
                                        if (msg == 'success') {
                                            msg = "操作成功！";
                                            BUI.Message.Alert(msg, function () {
                                                window.location.href = '/accounts/list.do';
                                            }, 'success')
                                        } else {
                                            msg = '操作失败'
                                            BUI.Message.Alert(msg, function () {
                                                window.location.href = '/jsp/error/noAuthority.jsp';
                                            }, 'error')
                                        }
                                    }
                                })
                            })
                        }
                    } else {
                        alert("必须和只能选择一个收据欠费信息")
                    }
                };
                var form = new Form.HForm({
                    srcNode: '#J_Form'
                });
            });
        </script>
    </div>
</div>
</body>
</html>
